package com.hig.risk.controller;

import java.util.List;

import com.hig.risk.domain.RiskSelfInspectionStatic;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskSelfInspection;
import com.hig.risk.service.IRiskSelfInspectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 重大隐患自查清单Controller
 * 
 * @author scp
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/risk/inspection")
public class RiskSelfInspectionController extends BaseController
{
    @Autowired
    private IRiskSelfInspectionService riskSelfInspectionService;

    /**
     * 查询重大隐患自查清单列表
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskSelfInspection riskSelfInspection)
    {
        startPage();
        List<RiskSelfInspection> list = riskSelfInspectionService.selectRiskSelfInspectionList(riskSelfInspection);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('risk:inspection:staticlist')")
    @GetMapping("/staticList")
    public TableDataInfo staticList(RiskSelfInspection riskSelfInspection)
    {
        startPage();
        List<RiskSelfInspectionStatic> list = riskSelfInspectionService.selectStaticList(riskSelfInspection);
        return getDataTable(list);
    }

    /**
     * 导出重大隐患自查清单列表
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:export')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(RiskSelfInspection riskSelfInspection, HttpServletResponse response)
    {
        List<RiskSelfInspection> list = riskSelfInspectionService.selectRiskSelfInspectionList(riskSelfInspection);
        ExcelUtil<RiskSelfInspection> util = new ExcelUtil<RiskSelfInspection>(RiskSelfInspection.class);
        util.exportExcel(response,list, "重大隐患自查清单数据", "重大隐患自查清单数据");
        return AjaxResult.success();
    }
    @PreAuthorize("@ss.hasPermi('risk:inspection:staticexport')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportStatic")
    public AjaxResult exportStatic(RiskSelfInspection riskSelfInspection, HttpServletResponse response)
    {
        List<RiskSelfInspectionStatic> list = riskSelfInspectionService.selectStaticList(riskSelfInspection);
        ExcelUtil<RiskSelfInspectionStatic> util = new ExcelUtil<RiskSelfInspectionStatic>(RiskSelfInspectionStatic.class);
        util.exportExcel(response,list, "重大隐患自查清单数据", "重大隐患自查清单数据");
        return AjaxResult.success();
    }
    /**
     * 获取重大隐患自查清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskSelfInspectionService.selectRiskSelfInspectionById(id));
    }

    /**
     * 新增重大隐患自查清单
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:add')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskSelfInspection riskSelfInspection)
    {
        return toAjax(riskSelfInspectionService.insertRiskSelfInspection(riskSelfInspection));
    }

    /**
     * 修改重大隐患自查清单
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:edit')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskSelfInspection riskSelfInspection)
    {
        return toAjax(riskSelfInspectionService.updateRiskSelfInspection(riskSelfInspection));
    }

    /**
     * 删除重大隐患自查清单
     */
    @PreAuthorize("@ss.hasPermi('risk:inspection:remove')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskSelfInspectionService.deleteRiskSelfInspectionByIds(ids));
    }
    @GetMapping("/overtime")
    public AjaxResult overtime()
    {
        RiskSelfInspection riskSelfInspection = new RiskSelfInspection();
        return riskSelfInspectionService.selectOvertime(riskSelfInspection);
    }

    @PreAuthorize("@ss.hasPermi('risk:inspection:staticadd')")
    @Log(title = "重大隐患自查清单", businessType = BusinessType.INSERT)
    @PostMapping("/all")
    public AjaxResult addAll(@RequestBody RiskSelfInspectionStatic riskSelfInspection)
    {
        return toAjax(riskSelfInspectionService.insertAllRiskSelfInspection(riskSelfInspection));
    }

    @PreAuthorize("@ss.hasPermi('risk:inspection:removeall')")
    @Log(title = "重大隐患自查清单删除", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult removeAll(@RequestBody RiskSelfInspectionStatic riskSelfInspection)
    {
//        System.out.println(param);
        return toAjax(riskSelfInspectionService.deleteRiskSelfInspection(riskSelfInspection));
    }
}
